import 'package:fluro/fluro.dart';
import 'package:flutter/material.dart';
import 'package:flutter_demo/pages/Login/PhoneLogin.dart';

// 界面
import '../pages/Login/LoginWay.dart';
import '../pages/Index/Index.dart';

const timeout = const Duration(seconds: 5);

class RouterConfig {
  static final router = FluroRouter();
  // 路由初始化
  static void initRouter() {
    // handle控制器
    var routesHandleList = {
      "/login": Handler(
        handlerFunc: (ctx, params) {
          return LoginWay();
        },
      ),
      "/index": Handler(
        handlerFunc: (ctx, params) {
          Map props = {};
          params.forEach((key, value) {
            props[key] = value[0];
          });
          return Index();
        },
      ),
      "/phoneLogin": Handler(
        handlerFunc: (ctx, params) {
          Map props = {};
          params.forEach((key, value) {
            props[key] = value[0];
          });
          return PhoneLogin();
        },
      )
    };
    routesHandleList.forEach((key, value) {
      // 注册路由handler
      router.define(key, handler: value);
    });
  }

// 界面跳转
  static navigater(BuildContext context,
      {transition: TransitionType.inFromRight, String path: '', type: 'push'}) {
    switch (type) {
      case 'push':
        return router.navigateTo(context, path, transition: transition);
      case 'back':
        return router.pop(context);
      case 'redirect':
        return router.navigateTo(context, path,
            transition: transition, replace: true);
      case 'relaunch':
        return router.navigateTo(context, path,
            transition: transition, clearStack: true);
      default:
        return router.navigateTo(context, path, transition: transition);
    }
  }
}
